<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>采购单</title>
		<link rel="stylesheet" type="text/css" href="../../../Themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="../../../Themes/icon.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/demo.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/common.css">
	</head>
	<style type="text/css">
		#fm {
			text-align: center;
		}
	</style>

	<body style="padding: 0px;">
		<div id="toolbar" class="receipts_toolbar_style"></div>
		<div class="easyui-layout" data-options="fit:true" style="width: 98%;">
			<div id="searchOption" data-options="region:'north',title:'查询条件',split:true" style="height:150px;width:100%">

			</div>
			<div data-options="region:'center',split:true" style="width:100%;height: 200px;">
				<div class="easyui-panel" style="width:100%;height:100%;padding:0px;">
					<table id="dg" style="width: 100%;" class="table_style">
					</table>
				</div>
			</div>

			<div id="addFrame" class="easyui-dialog" style="width:400px;height:400px;padding: 30px 30px;margin-left:;" data-options="title:'查询',buttons:'#bb',closed:true">
				<form id="fm" style="margin: 0px 0px ;" method="post">
				</form>
			</div>
		</div>
	</body>
	<script type="text/javascript" src="../../../JS/jquery.min.js"></script>
	<script type="text/javascript" src="../../../JS/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="../../../JS/common.js"></script>
	<script type="text/javascript" src="../../../JS/buildDialogSearch.js"></script>
	<script type="text/javascript">
		var globelOption = '';//保存查询参数
		var searchType = SEARCH_CREATE_MAN + SEARCH_INTERNAL_TYPE;
		searchType += SEARCH_STOREHOUSE_NAME_UNNECESSARY + SEARCH_INTERNAL_NAME + SEARCH_CUSTOMER_NAME + SEARCH_CREATE_TIME_START + SEARCH_CREATE_TIME_END;
		$('#searchOption').append(constructSearchOptionFormat(searchType, ""));
		var content = buildSearchOptions(searchType, "");
		$("#fm").append(content);
		constructDataGridData();
		initCombobox();

		function initCombobox() {
			
			//配送单位
			$('#search_customr_name').combobox({
				valueField: 'CUSTOMER_NAME',
				textField: 'CUSTOMER_NAME',
				panelHeight: 200,
				mode: 'remote',
				method: 'get',
				url: RemoteLinkAddress + "/logistics/customer/listall.do",
			});
			//商品名称
			$('#search_commodity_name').combobox({
				valueField: 'INTERNAL_NAME',
				textField: 'INTERNAL_NAME',
				panelHeight: 200,
				mode: 'remote',
				method: 'get',
				url: RemoteLinkAddress + "/logistics/internaltrade/listall.do",
				onChange: function(newValue, oldValue) {
					if(!isEnglish(newValue)) {
						return;
					}
					if(newValue != "" && newValue != undefined) {
						var url = RemoteLinkAddress + "/logistics/internaltrade/findbypinyin?PINYINFIELDNAME=" + newValue.trim();
						$(this).combobox("reload", url);
					}
				},
			});
			//商品类型
			$('#search_internal_type').combobox({
				valueField: 'INTERNAL_TYPE',
				textField: 'INTERNAL_TYPE',
				panelHeight: 200,
				mode: 'remote',
				method: 'get',
				editable: false,
				url: RemoteLinkAddress + "/logistics/internaltradetype/listall.do",
			});
			//库房名称
			$('#search_storehouse').combobox({
				valueField: 'NAME',
				textField: 'NAME',
				panelHeight: 200,
				mode: 'remote',
				method: 'get',
				editable: false,
				url: RemoteLinkAddress + "/logistics/storehouse/listall.do",
			});
		}

		function doSearch() {
			var isValid = $("#fm").form('validate');
			if(!isValid) {
				$.messager.alert("警告", "有必填项没有填写");
				return;
			}
			var searchCondition = processSearchCondition(true);
			var _url = RemoteLinkAddress + '/logistics/purchaseorder/findbydetail.do?' + searchCondition;
			globelOption = searchCondition;
			getRemoteData(_url);
			$('#addFrame').dialog('close');
		}

		function getRemoteData(_url) {
				$.ajax({
					type: "get",
					url: _url,
					dataType: 'json',
					success: function(result) {
						$('#dg').datagrid('loadData', result.rows);
					},
					error: function(error) {

					}
				});
			}

		function closeForm() {
			$('#addFrame').dialog('close');
		}

		function searchmore() {

			$("#addFrame").dialog('open').dialog('center');
			$('#fm').form('clear');
		}

		//导出
		function exportExcel(){
			var _url = RemoteLinkAddress + '/logistics/purchaseorder/findbydetail/excel.do'
			if(globelOption.length > 0){
				_url += '?' + globelOption;
			}
			$.messager.confirm("提示", "确认导出Excel表格吗？", function(r) {
			if(r) {
				$.ajax({ //调用ajax方法，从服务器获取到该订单的所有数据
					type: "get",
					dataType: "json", //服务器返回的数据类型
					url: _url,
					success: function(result) {
						window.location.href = result.path;
					}, //请求成功后，接受服务器传来的Json字符串，并做相应的处理
					error: function(xhr, status, error) {
						$.messager.alert("错误", "请求失败!");
						}
					});
				}
			});
		}

		content = AddReceiptsToolBar(1024 + 128, ""); /**根据用户的权限，来决定生成ToolBar的哪些功能**/
		$("#toolbar").append(content); /*在ID=toolbar的标记后面添加content中的内容*/
		function constructDataGridData() {
			$('#dg').datagrid({
				// url: RemoteLinkAddress + '/logistics/purchaseorder/findbydetail.do',
				method: 'get',
				rownumbers: 'true',
				autoRowHeight: 'true',
				fitColumns: 'false',
				singleSelect: 'true',
				height: 338,
				pagination: true,
				/*表格中的列名以及各自列名的ID*/
				columns: [
					[ {
							field: 'ORDER_NO',
							title: '采购单编号',
							width: '8%',
							align: 'center'
						},{
							field: 'PURCHASE_MAN',
							title: '采购员',
							width: '8%',
							align: 'center'
						},{
							field: 'INTERNAL_NAME',
							title: '商品名称',
							width: '10%',
							align: 'center'
						},{
							field: 'INTERNAL_TYPE',
							title: '商品类型',
							width: '10%',
							align: 'center'
						},{
							field: 'STOREHOUSE_NAME',
							title: '仓库名称',
							width: '10%',
							align: 'center'
						}, {
							field: 'PURCHASE_DATE',
							title: '采购时间',
							width: '10%',
							align: 'center'
						},{
							field: 'EVALUATE_AMOUNT',
							title: '预采数量',
							width: '10%',
							align: 'center'
						},{
							field: 'REAL_AMOUNT',
							title: '实采数量',
							width: '10%',
							align: 'center'
						},{
							field: 'DETAIL_STATE',
							title: '订单状态',
							width: '8%',
							align: 'center'
						},{
							field: 'ISVERIFY',
							title: '是否审核',
							width: '8%',
							align: 'center',
							formatter: function(value, row, index) {
								return verifyStatus(value, false);
							}

						}
					]
				],
				onDblClickRow: function(index, row) {
					var pLocation = "";
					pLocation = "UI/LOGISTICS/PurchaseOrder/PurchaseOrderAdd.html?id=" + row.ID; /*将BoothManagementAdd.html的相对路径与被选中行的ID赋值给pLocation*/
					AddTabIn("采购订单详情", parent.$("#tabs"), pLocation);
				},
			});
		}
	</script>

</html>